﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SCALP.Instruction
{
    /// <summary>
    /// Class containing methods for managing RAM and Registers
    /// </summary>
    public static class Memory
    {
        /// <summary>
        /// Enumerable containing registers
        /// </summary>
        public enum Registers
        {
            PC,
            IP,
            SP,
            SS,
            A,
            AL,
            AH,
            B,
            BL,
            BH,
            C,
            CL,
            CH,
            X,
            Y
        }
        /// <summary>
        /// Gets the numerical representation for the register
        /// </summary>
        /// <param name="reg">Register to get the numerical representation for</param>
        /// <returns>The numerical representation for that register</returns>
        public static byte getRegister(string reg)
        {
            // go through each register to see if the provided string is equal to that,
            //  return the correct value if equal. Return 0 if not.
            if (reg == "PC")
            {
                return 0xF0;
            }
            else if (reg == "IP")
            {
                return 0xF1;
            }
            else if (reg == "SP")
            {
                return 0xF2;
            }
            else if (reg == "SS")
            {
                return 0xF3;
            }
            else if (reg == "A")
            {
                return 0xF4;
            }
            else if (reg == "AL")
            {
                return 0xF5;
            }
            else if (reg == "AH")
            {
                return 0xF6;
            }
            else if (reg == "B")
            {
                return 0xF7;
            }
            else if (reg == "BL")
            {
                return 0xF8;
            }
            else if (reg == "BH")
            {
                return 0xF9;
            }
            else if (reg == "C")
            {
                return 0xFA;
            }
            else if (reg == "CL")
            {
                return 0xFB;
            }
            else if (reg == "CH")
            {
                return 0xFC;
            }
            else if (reg == "X")
            {
                return 0xFD;
            }
            else if (reg == "Y")
            {
                return 0xFE;
            }
            else
            {
                return 0;
            }
        }
        /// <summary>
        /// Sees if the provided string is a register
        /// </summary>
        /// <param name="regStr">String to check</param>
        /// <returns>If the string is a register</returns>
        public static bool isRegister(string regStr)
        {
            // go through each register to see if the provided string is equal to that,
            //   if so return true, if not return false
            if (regStr == "PC")
                return true;
            else if (regStr == "IP")
                return true;
            else if (regStr == "SP")
                return true;
            else if (regStr == "SS")
                return true;
            else if (regStr == "A")
                return true;
            else if (regStr == "AL")
                return true;
            else if (regStr == "AH")
                return true;
            else if (regStr == "B")
                return true;
            else if (regStr == "BL")
                return true;
            else if (regStr == "BH")
                return true;
            else if (regStr == "C")
                return true;
            else if (regStr == "CL")
                return true;
            else if (regStr == "CH")
                return true;
            else if (regStr == "X")
                return true;
            else if (regStr == "Y")
                return true;
            else
                return false;
        }
    }
}
